home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / psort / example / fast.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  3.3 KB  |  180 lines

  1. /* *****************************************************************************
  2. *
  3. * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  4. * All Rights Reserved.
  5. *
  6. * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  7. * the contents of this file may not be disclosed to third parties, copied or
  8. * duplicated in any form, in whole or in part, without the prior written
  9. * permission of Silicon Graphics, Inc.
  10. *
  11. * RESTRICTED RIGHTS LEGEND:
  12. * Use, duplication or disclosure by the Government is subject to restrictions
  13. * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  14. * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  15. * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  16. * rights reserved under the Copyright Laws of the United States.
  17. *
  18. ***************************************************************************** */
  19. #include <gl.h>
  20. #include <device.h>
  21. #include <math.h>
  22. #include "fast.h"
  23. #include "event.h"
  24.  
  25. extern int mainmenu, quitmenu;
  26.  
  27. void display();
  28.  
  29. int do_exit;
  30. int ask_quit;
  31.  
  32. int max_size, this_size;
  33. int this_proc;
  34.  
  35. int *image, *show_image;
  36. int *my_index;
  37.  
  38. double this_time, this_flop;
  39. extern int x_size, y_size, n_total;
  40. char message[64];
  41. void InitFast(char *filename);
  42. double second();
  43.  
  44. int do_compar(int *, int *);
  45.  
  46. fast (char *filename)
  47. {
  48.     InitFast(filename);
  49.     Init(filename);
  50.  
  51.     do_exit = FALSE;
  52.  
  53.     display();
  54.     
  55.     while(! do_exit) {
  56.         event();
  57.     }
  58. }
  59.  
  60. ShowFast()
  61. {
  62.     char str[32];
  63.  
  64.     cpack (oBLACK);
  65.     clear ();
  66.  
  67.      cpack (oGREEN);
  68.     ortho2(0,ZOOM_FACTOR*x_size+2*BORDER,0, ZOOM_FACTOR*y_size+2*BORDER);
  69.     cmov2i( 250, ZOOM_FACTOR*y_size+BORDER+20);
  70.     sprintf( str, "SIZE = %d x %d", x_size, y_size);
  71.     charstr(str);
  72.  
  73.     cmov2i( 200, 20);
  74.     charstr(message);
  75.  
  76.     DrawFast();
  77. }
  78.  
  79. void do_quit()
  80. {
  81.     gexit();
  82.     exit(0);
  83. }
  84.  
  85.  
  86. void do_rightmouse()
  87. {
  88.     ask_quit = 0;
  89.  
  90.     dopup(mainmenu);
  91.  
  92.     if(ask_quit)
  93.     dopup(quitmenu);
  94.  
  95. }
  96.  
  97. void display()
  98. {
  99.     reshapeviewport();
  100.     ShowFast();
  101.     swapbuffers();
  102. }
  103.  
  104. void do_reset(){
  105.     
  106.     int i;
  107.     for(i= 0; i < n_total; i++)
  108.     my_index[i] = i;
  109.     do_mix();
  110.     strcpy(message,"");
  111.     display();
  112. }
  113.  
  114. do_shuffle(){
  115.     int i, j, k;
  116.     for( i = 0; i < n_total; i++){
  117.     j = random() % n_total;
  118.     k = my_index[i];
  119.     my_index[i] = my_index[j];
  120.     my_index[j] = k;
  121.     }
  122.     do_mix();
  123.     strcpy(message,"");
  124.     display();
  125. }
  126.  
  127. do_mix(){
  128.     int i;
  129.     for(i = 0; i< n_total; i++)
  130.     show_image[i] = image[my_index[i]];
  131. }
  132.  
  133. void this_run(){
  134.  
  135.     this_time = second();
  136.     qsort(my_index, n_total, sizeof(int), do_compar);
  137.     this_time = second() - this_time;
  138.     do_mix();
  139.     sprintf(message, "Qsort done in %.2f Seconds",this_time);
  140.     display();
  141. }
  142.  
  143. void that_run(){
  144.  
  145.     this_time = second();
  146.     psort(my_index, n_total, sizeof(int), do_compar);
  147.     this_time = second() - this_time;
  148.     do_mix();
  149.     sprintf(message, "Psort done in %.2f Seconds",this_time);
  150.     display();
  151. }
  152.  
  153. void update_(int *k){
  154.     this_size = *k;
  155.  
  156.     display();
  157. }
  158.  
  159. void this_quit(){
  160.  
  161.     ask_quit = 1;
  162. }
  163. void InitFast(char *filename){
  164.  
  165.     this_proc = mpc_numthreads();
  166.     readrgb(filename);
  167.     show_image = (int *)malloc(n_total * sizeof(int));
  168.     my_index = (int *)malloc(n_total * sizeof(int));
  169. }
  170.  
  171. int do_compar( int *a, int *b)
  172. {
  173.     if( (*a) < (*b)) 
  174.     return (-1);
  175.     if( (*a) > (*b))
  176.     return (1);
  177.     return (0);
  178. }
  179.  
  180.